﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LIT.Logger.ServerCheckerBL
{
    public interface IConfiguration
    {
        int DiskSpaceLowLimitMB { get; }
        List<char> CheckLowDiskSpaceDriveLetters { get; }
        List<string> WindowsEventLogSourcesToSend { get; }
        string MinWindowsEventLogPriority { get; }
        bool SendIsAlive { get; }
        List<string> CheckServices { get; }
        List<string> CheckProcesses { get; }
        List<string> CheckComputerCertificateStores { get; }
        List<string> CheckUserCertificateStores { get; }
        List<string> IgnoreCertificateThumbnails { get; }
    }

    public class Configuration : IConfiguration
    {
        private int? m_diskSpaceLowLimitMB;
        public int DiskSpaceLowLimitMB
        {
            get
            {
                if (!m_diskSpaceLowLimitMB.HasValue)
                    m_diskSpaceLowLimitMB = Properties.Settings.Default.DiskSpaceLowLimitMB;
                return m_diskSpaceLowLimitMB.Value;
            }
        }

        private List<char> m_checkLowDiskSpaceDriveLetters;
        public List<char> CheckLowDiskSpaceDriveLetters
        {
            get
            {
                if (m_checkLowDiskSpaceDriveLetters == null)
                {
                    m_checkLowDiskSpaceDriveLetters = new List<char>();
                    foreach (string str in Properties.Settings.Default.CheckLowDiskSpaceDriveLetters)
                        if (!String.IsNullOrWhiteSpace(str))
                            m_checkLowDiskSpaceDriveLetters.Add(str[0]);
                }
                return m_checkLowDiskSpaceDriveLetters;
            }
        }

        private List<string> m_windowsEventLogSourcesToSend;
        public List<string> WindowsEventLogSourcesToSend
        {
            get
            {
                if (m_windowsEventLogSourcesToSend == null)
                {
                    m_windowsEventLogSourcesToSend = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.WindowsEventLogSourcesToSend)
                        m_windowsEventLogSourcesToSend.Add(tmp);
                }
                return m_windowsEventLogSourcesToSend;
            }
        }

        private string m_minWindowsEventLogPriority;
        public string MinWindowsEventLogPriority
        {
            get
            {
                if (String.IsNullOrWhiteSpace(m_minWindowsEventLogPriority))
                    m_minWindowsEventLogPriority = Properties.Settings.Default.MinWindowsEventLogPriority;
                return m_minWindowsEventLogPriority;
            }
        }

        private bool? m_sendIsAlive;
        public bool SendIsAlive
        {
            get
            {
                if (!m_sendIsAlive.HasValue)
                    m_sendIsAlive = Properties.Settings.Default.SendIsAlive;
                return m_sendIsAlive.Value;
            }
        }

        private List<string> m_checkServices;
        public List<string> CheckServices
        {
            get
            {
                if (m_checkServices == null)
                {
                    m_checkServices = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.CheckServices)
                        m_checkServices.Add(tmp);
                }
                return m_checkServices;
            }
        }

        private List<string> m_checkProcesses;
        public List<string> CheckProcesses
        {
            get
            {
                if (m_checkProcesses == null)
                {
                    m_checkProcesses = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.CheckProcesses)
                        m_checkProcesses.Add(tmp);
                }
                return m_checkProcesses;
            }
        }

        private List<string> m_checkComputerCertificateStores;
        public List<string> CheckComputerCertificateStores 
        {
            get
            {
                if (m_checkComputerCertificateStores == null)
                {
                    m_checkComputerCertificateStores = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.CheckComputerCertificateStores)
                        m_checkComputerCertificateStores.Add(tmp);
                }
                return m_checkComputerCertificateStores;
            }
        }

        private List<string> m_checkUserCertificateStores;
        public List<string> CheckUserCertificateStores 
        {
            get
            {
                if (m_checkUserCertificateStores == null)
                {
                    m_checkUserCertificateStores = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.CheckUserCertificateStores)
                        m_checkUserCertificateStores.Add(tmp);
                }
                return m_checkUserCertificateStores;
            }
        }

        private List<string> m_ignoreCertificateThumbnails;
        public List<string> IgnoreCertificateThumbnails 
        {
            get
            {
                if (m_ignoreCertificateThumbnails == null)
                {
                    m_ignoreCertificateThumbnails = new List<string>();
                    foreach (string tmp in Properties.Settings.Default.IgnoreCertificateThumbnails)
                        m_ignoreCertificateThumbnails.Add(tmp);
                }
                return m_ignoreCertificateThumbnails;
            }
        }
    }
}
